<script type="text/javascript">
    var oTable;
    $(document).ready(function(){
        oTable = $('#link_table').dataTable({
            "bJQueryUI": true,
			"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
			"sPaginationType": "bootstrap",
            "aaSorting": [[ 2, "desc" ]],
			"oLanguage": {
			"sLengthMenu": "_MENU_ records per page"
			}
		} );
        $(".date-picker").datepicker({
    		dateFormat : 'yy-mm-dd',
    		"maxDate" : "-0D"
    	});
        
        $(".chose_type").click(function(){
            var type = this.getAttribute("_type");
            $("#type").val(type);
        });
    });
</script> 
<style type="text/css">
.select_form form{
    display: inline-flex;
}
.select_form label{
    line-height: 30px;
}
.select_form input[type='text']{
    margin: 0px 10px;
}
.select_form button{
    margin: 0px 10px;
}
</style>
<h3>Thống kê</h3>
<div class="select_form" style="margin-top: 10px">
    <form action='/user/index/index' method='post'>       
        <label>Từ ngày:</label>
            <input type="text" name="from" class="date-picker" value="<?php echo $this->from; ?>" />
        <label>Đến ngày:</label>
            <input type="text" name="to" class="date-picker" value="<?php echo $this->to; ?>" />
            <input type="hidden" id="type" name="type" value="<?php echo !empty($this->type) ? $this->type : "1";?>" />
        <button class="btn btn-normal btn-inverse chose_type" _type="1">Xem theo widget</button>
        <button class="btn btn-normal btn-inverse chose_type" _type="2">Xem theo link</button> 
    </form>	
</div>
<?php if($this->type == 1){ ?>
<div class="row-fluid sortable">		
	<div class="box span12">
		<div class="box-header" data-original-title>
			<h2><i class="icon-user"></i><span class="break"></span>Thống kê theo Widget</h2>
		</div>
		<div class="box-content">
			<table class="table table-striped table-bordered bootstrap-datatable datatable" id="link_table">
            	<thead>
                  	<tr>
            			<th>STT</th>
            			<th>Widget's name</th>
                        <th>Link Web</th>
                        <th>Impress</th>
                        <th>Clicks</th>
                        <th>CPR</th>
            		</tr>
                </thead>
                <?php 
                        $list = $this->list;
                        if(count($list) && $list[0]['name']!=null){ 
                ?>
                <tbody>
                    <?php
                            $x = 0;
                            $total_impress = 0;
                            $total_click = 0; 
                    ?>
                        <?php foreach($list as $item){ 
                            $total_impress += $item['impress'];
                            $total_click += $item['clicks'];
                    ?>
                    <tr>
                        <td><?php echo $x; ?></td>
            			<td><?php echo $item['name']; ?></td>
                        <td><?php echo $item['link_web']; ?></td>
                        <td><?php echo number_format($item['impress']); ?></td>
                        <td><?php echo number_format($item['clicks']); ?></td>
                        <td><?php echo number_format(round($item['clicks']/$item['impress']*100, 2)); ?></td>
                    </tr>
                    <?php }// end foreach?>
                </tbody>
            	<tfoot>
            		<tr>
            			<th colspan="3">Tổng</th>
            			<th><?php echo number_format($total_impress); ?></th>
                        <th><?php echo number_format($total_click); ?></th>
                        <th><?php echo number_format(round($total_click/$total_impress*100, 2)); ?></th>
            		</tr>
            	</tfoot>
                <?php }// end if?>		
            </table>   
        </div>
	</div><!--/span-->
</div><!--/row-->
<hr />  
<?php }else if($this->type == 2){ ?>
<div class="row-fluid sortable">		
	<div class="box span12">
		<div class="box-header" data-original-title>
			<h2><i class="icon-user"></i><span class="break"></span>Thống kê theo link</h2>
		</div>
		<div class="box-content">
			<table class="table table-striped table-bordered bootstrap-datatable datatable" id="link_table">
            	<thead>
                  	<tr>
            			<th>STT</th>
            			<th>Link's title</th>
                        <th>Impress</th>
                        <th>Clicks</th>
                        <th>CPR</th>
            		</tr>
                </thead>
                <?php 
                        $list = $this->list;
                        if(count($list) && $list[0]['title']!=null){ 
                ?>
                <tbody>
                    <?php
                            $x = 0;
                            $total_impress = 0;
                            $total_click = 0; 
                    ?>
                        <?php foreach($list as $item){ 
                            $total_impress += $item['impress'];
                            $total_click += $item['clicks'];
                    ?>
                    <tr>
                        <td><?php echo $x; ?></td>
            			<td><?php echo $item['title']; ?></td>
                        <td><?php echo number_format($item['impress']); ?></td>
                        <td><?php echo number_format($item['clicks']); ?></td>
                        <td><?php echo number_format(round($item['clicks']/$item['impress']*100, 2)); ?></td>
                    </tr>
                    <?php }// end foreach?>
                </tbody>
            	<tfoot>
            		<tr>
            			<th colspan="2">Tổng</th>
            			<th><?php echo number_format($total_impress); ?></th>
                        <th><?php echo number_format($total_click); ?></th>
                        <th><?php echo number_format(round($total_click/$total_impress*100, 2)); ?></th>
            		</tr>
            	</tfoot>
                <?php }// end if?>		
            </table>   
        </div>
	</div><!--/span-->
</div><!--/row-->
<hr />    
<?php }?>